
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path =request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>添加部门</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="<%=basePath%>resources/css/font.css">
    <link rel="stylesheet" href="<%=basePath%>resources/css/xadmin.css">
    <script type="text/javascript" src="<%=basePath%>resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath%>resources/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <%--富文本--%>
    <link rel="stylesheet" href="http://www.jq22.com/jquery/bootstrap-3.3.4.css">
    <link href="<%=basePath%>resources/dist/summernote.css" rel="stylesheet"/>
    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <script src="http://www.jq22.com/jquery/bootstrap-3.3.4.js"></script>
    <script src="<%=basePath%>resources/dist/summernote.js"></script>
    <script src="<%=basePath%>resources/dist/lang/summernote-zh-CN.js"></script>

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="id" class="layui-form-label">
                    <span class="x-red">*</span>部门ID
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="id" name="id" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将成为部门唯一的ID
                </div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>部门名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="phone"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将成为唯一部门名
                </div>
            </div>
            <div class="summernote">

            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" onclick="add()">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    $(function(){
        $('.summernote').summernote({
            height:250,
            tabsize: 2,
            lang: 'zh-CN'
        });
    })
/*    function add(){
        var a_note = $('.summernote').summernote('code');
        var formData = $("form").serialize();
        alert(formData);
        $.ajax({
            url:"<%=basePath%>Department/Add?a_note="+a_note+"&formData="+formData,
            success : function (data){
                if(data.flag){
                    location.href="<%=basePath%>Department/department";
                }
            }
        })
    }*/
    function add(){
        var a_note = $('.summernote').summernote('code');
        //var data = $("form").serialize();
        var name = $("#name").val();
        var id = $("#id").val();
        /*var formDate = new FormData();
        formDate.append("a_note",a_note);
        formDate.append("data",data);*/
        $.ajax({
            url:"<%=basePath%>Department/Add",
            type:"post",
            data: {"note":a_note,"department_name":name,"department_id":id},
            success:function (d){
                if(d.flag){
                    location.href="<%=basePath%>Department/department";
                };
            }
        })
    }
    //监听提交
/*    form.on('submit(add)',
        function(data) {
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", {
                    icon: 6
                },
                function() {
                    //关闭当前frame
                    xadmin.close();

                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            return false;
        });*/
</script>

</html>

